package cn.itcast.dao;

import cn.itcast.utils.DruidUtils;
import com.alibaba.druid.pool.DruidDataSource;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.ColumnListHandler;

import java.sql.SQLException;
import java.util.List;

public class UserDao {
    //构建语句执行者
    private QueryRunner qr = new QueryRunner(DruidUtils.getDataSource());

    //实现一个工呢 完成关键字模糊查询
    public List<String> search(String keyword) throws SQLException {
        //根据关键字进行查询
       String sql = "select name from user where name like ?";
       //只要带张就 联想
        Object[] params = {"%"+keyword+"%"};
        return qr.query(sql,new ColumnListHandler<String>(),params);

    }
}
